package com.hc.util;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hc.entity.SysUserInfo;
import com.hc.service.SysUserInfoService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author LiuZhiHao
 * @date 2019/9/10 16:11
 * 描述:
 **/
@Service
public class UserInfoPostImpl implements UserInfoPost {

    @Autowired
    private SysUserInfoService sysUserInfoService;

    @Override
    public Map<String, String> getAllSysUserinfoByIds(Set<String> ids) {
        List<SysUserInfo> list = null;
        if (CollectionUtils.isEmpty(ids)){
            list=  sysUserInfoService.list();
        }else {
            list=sysUserInfoService.list(Wrappers.lambdaQuery(new SysUserInfo()).in(SysUserInfo::getUserId, ids));
        }
        Map<String, List<SysUserInfo>> collect = list.stream().collect(Collectors.groupingBy(SysUserInfo::getUserId));
        Map<String, String> map = new HashMap<>();
        collect.forEach((key, value) -> {
            SysUserInfo sysUserInfo = value.get(0);
            map.put(key, sysUserInfo.getName());
        });
        return map;
    }


}
